//
//  WalletViewController.m
//  NiuBanJin
//
//  Created by Billy on 15/10/10.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "WalletViewController.h"
#import "WalletCenterView.h"
#import "TicketExcahngeAndSigningController.h"
#import "IncomeViewController.h"
#import "IDCardAuthenticationViewController.h"
#import "TicketsViewController.h"
#import "AssetDetailsViewController.h"
#import "User.h"
#import "BankCardBindingViewController.h"
#import "RegisterViewController.h"
#import "DepositViewController.h"
#import "WebViewController.h"
@interface WalletViewController ()<WalletCenterViewDelegate,UIGestureRecognizerDelegate , UIAlertViewDelegate>

@property (nonatomic, strong) UIView *view_header; // 顶部红色view
@property (nonatomic, strong) UIView *view_content; // 中间内容view
@property (nonatomic, strong) UIButton *button_saveMoney;
@property (nonatomic, assign) NSInteger defaultTag;
@property (nonatomic, assign) BOOL str_isSignSuccess ;// 验证用户是不是签到成功
@property (nonatomic, copy) NSString *str_signScore ;// 签到获得的积分
@property (nonatomic, strong)NSMutableDictionary *mutableDictionary_data; //当前页面数据源
@property (nonatomic, strong) UIView *view_bottom; //底部协议文案


@end

@implementation WalletViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self pageSettingsAndSubviewsCreation];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self getDataFromServer];
}


#pragma mark - SubviewsCreationAndPageSettings

- (void) pageSettingsAndSubviewsCreation {
    
       // 禁用主界面的返回按钮
    [self.navigationItem setLeftBarButtonItem:nil];
    [self.navigationItem setTitle:@"牛钱包"];
    
    self.defaultTag  = 40;
    [self.view addSubview:self.view_header];
    [self.view addSubview:self.view_content];
    [self.view addSubview:self.button_saveMoney];
    [self.view addSubview:self.view_bottom];
    
    // 设置右上角按键
    [self setRightBarButtonItemTitle:@"签到" imageName:@"signing" actionName:@selector(buttonClickedAtWalletPage:)];
}


#pragma mark - data prepation

- (void) getDataFromServer {
    
    NSDictionary *dic_params = @{@"userId":GETCURRENTUSERINOBYPRAMETERES(user_userId),@"token":GETCURRENTUSERINOBYPRAMETERES(user_userToken)};
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [[NetworkUtil sharedNetworkUtil] zzjrGetUserAssetsByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if (!error) {
            
            NSDictionary *dic_result = parsedData;
            
            if ([dic_result[@"status"] integerValue] == 0) { //正确得到数据
                
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"asset"] forKey:@"asset"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"annualRate"] forKey:@"annualRate"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"ticketRate"] forKey:@"ticketRate"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"dayProfit"] forKey:@"dayProfit"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"totalPayoff"] forKey:@"totalPayoff"];
                [self.mutableDictionary_data setObject:dic_result[@"result"][@"profitType"] forKey:@"profitType"];
                
                User *user = [[UserManager sharedUserManager] getCurrentUser];
                
                user.user_isCardBinding = dic_result[@"result"][@"cardBinding"];
                user.user_userScores = dic_result[@"result"][@"scores"];
                
                [[UserManager sharedUserManager] saveCurrentUser:user];
            }else {
                
                [UsefulUtil showAlertView:dic_result[@"msg"]];
            }
            
            if ([self.mutableDictionary_data count] > 0) {
                
                //update UI
                
                [self updateUI];
            }
        }else {
            
            [UsefulUtil showAlertView:error.description];
        }
    }];
}

- (void) updateUI { //在取得数据后更新UI
    
    // 总资产UI
    
    UILabel *label_asset = [self.view_header viewWithTag:10];
    [label_asset setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"asset"]]];
    
    // 年化收益UI
    
    UILabel *label_shown_annualRate= [[self.view_content viewWithTag:41] viewWithTag:11];
    
    //年利率
    NSString *str_annualRate = [NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"annualRate"]];
    
    // 加息利率
    NSString *str_addRate = [NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"ticketRate"]];
    
    if ([str_addRate integerValue] > 0) {

        WalletCenterView * tmp_view = [[self.view viewWithTag:80] viewWithTag:41];
        [tmp_view setIsRateAdding:[NSNumber numberWithBool:YES]];
        
        UIImageView *imageView_tmp = [[UIImageView alloc] initWithFrame:CGRectMake(MULTIPLYWIDTH(250.0/2),  MULTIPLYHEIGHT( 100.0/2), MULTIPLYWIDTH(50.0/2), MULTIPLYHEIGHT(66.0/2))];
        
        [imageView_tmp setImage:[UIImage imageNamed:@"up-fire"]];
        [tmp_view addSubview:imageView_tmp];

        NSString *str_content = [NSString stringWithFormat:@"%@%%+%@%%",str_annualRate,str_addRate];
        
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str_content];
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30.0] range:NSMakeRange(0, str_annualRate.length)];//8
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0] range:NSMakeRange(str_annualRate.length , 2)]; //%+
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30.0] range:NSMakeRange(str_annualRate.length+2 , str_addRate.length)]; //1
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0] range:NSMakeRange(str_content.length - 1, 1)]; //%

        [label_shown_annualRate setAttributedText:attrStr];
    }else {
        
        NSString *str_content = [NSString stringWithFormat:@"%@%%+0%%",str_annualRate];
        
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str_content];
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30.0] range:NSMakeRange(0, str_annualRate.length)];  //8
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0] range:NSMakeRange(str_annualRate.length , 2)]; //%+
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30.0] range:NSMakeRange(str_annualRate.length + 2, 1)];
        
        [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0] range:NSMakeRange(str_content.length-1, 1)];
        
        [label_shown_annualRate setAttributedText:attrStr];

    }
    
    // 累计收益
    
    UILabel *label_shown_profit = [[self.view_content viewWithTag:42] viewWithTag:11];
    [label_shown_profit setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"totalPayoff"]]];
    
    //每日万分收益
    
    UILabel *label_shown_dayProfit = [[self.view_content viewWithTag:43] viewWithTag:11];
    [label_shown_dayProfit setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"dayProfit"]]];
 
    //计息方式
    
    UILabel *label_dayProfitType = [[self.view_content viewWithTag:44] viewWithTag:11];
    [label_dayProfitType setText:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"profitType"]]];
}

#pragma mark - events handing

- (void) buttonClickedAtWalletPage: (UIButton *) button {
    
    switch (button.tag) {
            
        case 20: //存入
        {
                NSLog(@"money");
            
            if (![[UserManager sharedUserManager] isAuthentication]) { //没有实名认证
                
                // 跳到存入钱的logic
                
                IDCardAuthenticationViewController *authenticationVC = [[IDCardAuthenticationViewController alloc] init];
                authenticationVC.Type = 0;
                [authenticationVC setHidesBottomBarWhenPushed:YES];
                
                [self.navigationController pushViewController:authenticationVC animated:YES];
            }else  { //通过了实名认证
                
                if ([[UserManager sharedUserManager] isCardBinding]) { //已经绑定过卡,跳不同的存入界面

                    DepositViewController *deposeVC = [[DepositViewController alloc] init];
                    [deposeVC setHidesBottomBarWhenPushed:YES];
                    
                    [self.navigationController pushViewController:deposeVC animated:YES];
                }else {
                    
                    //跳到绑定存入page
                    BankCardBindingViewController *bankVC = [[BankCardBindingViewController alloc] init];
                    [bankVC setHidesBottomBarWhenPushed:YES];
                    
                    [self.navigationController pushViewController:bankVC animated:YES];
                }
            }
        }
            break;
            
        default: //签到
        {
            NSDictionary *dic_params = @{@"token" :[UserManager sharedUserManager].user.user_userToken , @"userId" : [UserManager sharedUserManager].user.user_userId};
           
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            
            [[NetworkUtil sharedNetworkUtil] zzjrScore_usersignByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {
                
                [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                
                if (!error) {
                    
                    NSDictionary *dic_result = (NSDictionary *) parsedData ;
                    
                    if ([dic_result[@"status"] integerValue] == 0) {
                        
                        self.str_isSignSuccess = YES;
                        self.str_signScore = dic_result[@"result"][@"todaySignScore"];
                        
                        //保存最新积分
                        
                        User *tmp = [[UserManager sharedUserManager] getCurrentUser];
                        tmp.user_userScores = dic_result[@"result"][@"score"];
                        [[UserManager sharedUserManager] saveCurrentUser:tmp];
                        
                        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@"获得积分:%@",self.str_signScore] message: nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                        
                        [alertView show];
                    }else if ([dic_result[@"status"] integerValue] == 3) {
                        
                        self.str_isSignSuccess = YES;
                        self.str_signScore = dic_result[@"result"][@"todaySignScore"];
                        
                        //保存最新积分
                        
                        User *tmp = [[UserManager sharedUserManager] getCurrentUser];
                        tmp.user_userScores = dic_result[@"result"][@"score"];
                        [[UserManager sharedUserManager] saveCurrentUser:tmp];
                        
                        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                        
                        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:dic_result[@"msg"] message: nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                        [alertView show];
                    }
                    
                }else {
                    
                    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                    [UsefulUtil showAlertView:error.description];
                }
            }];
  
        }
            break;
    }
}

- (void) textExplain:(UIButton *) button {
    
    switch (button.tag) {
        case 30: //投资协议
        {
            
            WebViewController *weVC = [[WebViewController alloc]init];
            weVC.index = 10;
            [self.navigationController pushViewController:weVC animated:YES];
        }
            break;
            
        case 31://什么是年钱包
        {
             [UsefulUtil showAlertView:@"跳什么是牛钱包H5"];
        }
            break;
        default:
            break;
    }
    
    
}


#pragma mark -alertView 

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (buttonIndex == 0) {
        
        TicketExcahngeAndSigningController *signingVC = [[TicketExcahngeAndSigningController alloc] init];
        [signingVC setType:@"sign"];
        [signingVC setHidesBottomBarWhenPushed:YES];
        [signingVC setStr_signScore:self.str_signScore];
        [self.navigationController pushViewController:signingVC animated:YES];
    }
}

- (void) tapGestureHandle: (UITapGestureRecognizer *) tap {
    
    NSLog(@"tap ...%@",tap.view);
    
    switch (tap.view.tag) {
        case 41: //年化收益
        {
            UITabBarController *tabbar = (UITabBarController *) CURRENT_WINDOW.rootViewController ;
            
            NSUInteger index = tabbar.selectedIndex;
            
            [tabbar setSelectedIndex:index+1];
        }
            break;
        case 42: //收益明细
        {
            IncomeViewController *incomeVC= [[IncomeViewController alloc] init];
            [incomeVC setStr_totayProfit:[NSString stringWithFormat:@"%@",self.mutableDictionary_data[@"totalPayoff"]]];
            [incomeVC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController: incomeVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}

- (void)showAssetListGesture:(UITapGestureRecognizer *) tap {
    
    AssetDetailsViewController *assetVC = [[AssetDetailsViewController alloc] init];
    [assetVC setHidesBottomBarWhenPushed:YES];
    
    [self.navigationController pushViewController:assetVC animated:YES];
}

#pragma mark - setter methods

- (UIView *)view_header {
    
    if (!_view_header) {
        
        _view_header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(421.0/2))];
        [_view_header.layer setContents:(__bridge id)[UIImage imageNamed:@"wave"].CGImage];
        
        // 总资产
        UILabel *label_assetPrompt = [UsefulUtil labelCreationWithFrame:CGRectMake(MULTIPLYWIDTH(290.0/2), MULTIPLYHEIGHT(78.0/2), MULTIPLYWIDTH(166.0/2), MULTIPLYHEIGHT(30.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:16.0] text:@"总资产 (元)"];
      
//        UILabel *label_assetPrompt = [UsefulUtil labelCreationWithFrame:CGRectMake(0, MULTIPLYHEIGHT(78.0/2), SCREEN_WIDTH, MULTIPLYHEIGHT(30.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:16.0] text:@"总资产 (元)"];
        [label_assetPrompt setTextAlignment:NSTextAlignmentCenter];
        [_view_header addSubview:label_assetPrompt];
        
        // 随存随取
        
        UIImageView *imageView_right = [UsefulUtil imageViewCreationWithFrame:CGRectMake(CGRectGetMaxX(label_assetPrompt.frame) + MULTIPLYWIDTH(150.0/2), MULTIPLYHEIGHT(70.0/2), MULTIPLYWIDTH(144.4/2), MULTIPLYHEIGHT(44.0/2)) image:[UIImage imageNamed:@"group1"]];
        
        [_view_header addSubview:imageView_right];
        
        //多少钱
        UILabel *label_assetValue = [UsefulUtil labelCreationWithFrame:CGRectMake(0, CGRectGetMaxY(label_assetPrompt.frame) + MULTIPLYHEIGHT(70.0/2), SCREEN_WIDTH, MULTIPLYHEIGHT(120.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:58.0] text:@"0.00"];
        [label_assetValue setTag:10];
        [label_assetValue setTextAlignment:NSTextAlignmentCenter];
        [label_assetValue setAdjustsFontSizeToFitWidth:YES];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showAssetListGesture:)];
        [tap setDelegate:self];
        [_view_header addGestureRecognizer:tap];
        
        [_view_header addSubview:label_assetValue];
        
        //保险图片+文案
        
        UIImageView *imageView_shield = [[UIImageView alloc] initWithFrame:CGRectMake(MULTIPLYWIDTH(193.0/2), CGRectGetMaxY(label_assetValue.frame)+MULTIPLYHEIGHT(42.0/2), MULTIPLYWIDTH(22.0/2), MULTIPLYHEIGHT(26.0/2))];
        [imageView_shield setImage:[UIImage imageNamed:@"shield"]];
        
        [_view_header addSubview:imageView_shield];
        
        UILabel *label_shield = [UsefulUtil labelCreationWithFrame:CGRectMake(MULTIPLYWIDTH(10.0/2) + CGRectGetMaxX(imageView_shield.frame), CGRectGetMaxY(label_assetValue.frame)+MULTIPLYHEIGHT(40.0/2), SCREEN_WIDTH - MULTIPLYWIDTH(214.0/2), MULTIPLYHEIGHT(30.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:13.0] text:@"资金交易安全由阳光保险承保"];
        
        [_view_header addSubview:label_shield];
        
    }
    return _view_header;
}

- (UIView *)view_content {
    
    if (!_view_content) {
        
        _view_content = [[UIView alloc] initWithFrame:CGRectMake(MULTIPLYWIDTH(30.0/2),  CGRectGetMaxY(self.view_header.frame)+ MULTIPLYHEIGHT(40.0/2), SCREEN_WIDTH- MULTIPLYWIDTH(60.0/2), MULTIPLYHEIGHT(380.0/2))];
        [_view_content setTag:80];
        [_view_content setBackgroundColor:BASECOLOR];
        
        // 竖 && 横白线
        
        UIView *view_vertical =  [UsefulUtil viewCreationWithFrame:CGRectMake(MULTIPLYWIDTH(345.0/2), 0, MULTIPLYWIDTH(2.0/2), MULTIPLYHEIGHT(380.0/2)) backgroundColor:[UIColor whiteColor] backGroundImage:nil];
        
        UIView *view_horizon = [UsefulUtil viewCreationWithFrame:CGRectMake(0, MULTIPLYHEIGHT(188.0/2), _view_content.bounds.size.width, MULTIPLYHEIGHT(2.0/2)) backgroundColor:[UIColor whiteColor] backGroundImage:nil];
        
        [_view_content addSubview:view_horizon];
        [_view_content addSubview:view_vertical];
        
        // 具体内容 ， 这儿想办法用模余算法弄成for-in,中间多了个白线，so 暂时不用
        
        WalletCenterView *view_content1 = [[WalletCenterView alloc] initWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(345.0/2), MULTIPLYHEIGHT(188.0/2)) title:@"年化收益" rate:@"8%" isRateAdding:[NSNumber numberWithBool:NO] isEnabledRightCornerICon:[NSNumber numberWithBool:YES]];
        [view_content1 setDelegate:self];

        [_view_content addSubview:view_content1];
        
        WalletCenterView *view_content2 = [[WalletCenterView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view_vertical.frame), 0, MULTIPLYWIDTH(345.0/2), MULTIPLYHEIGHT(188.0/2)) title:@"累计收益 (元)" rate:@"0.00" isRateAdding:[NSNumber numberWithBool:NO] isEnabledRightCornerICon:[NSNumber numberWithBool:YES]];
        [view_content2 setDelegate:self];
        
        [_view_content addSubview:view_content2];
        
        WalletCenterView *view_content3 = [[WalletCenterView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_horizon.frame), MULTIPLYWIDTH(345.0/2), MULTIPLYHEIGHT(188.0/2)) title:@"每日万元收益 (元)" rate:@"2.30" isRateAdding:[NSNumber numberWithBool:NO] isEnabledRightCornerICon:[NSNumber numberWithBool:NO]];
        [view_content3 setDelegate:self];
        
        [_view_content addSubview:view_content3];
        
        WalletCenterView *view_content4 = [[WalletCenterView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view_vertical.frame), CGRectGetMaxY(view_horizon.frame), MULTIPLYWIDTH(345.0/2), MULTIPLYHEIGHT(188.0/2)) title:@"计息方式" rate:@"按日复利计算" isRateAdding:[NSNumber numberWithBool:NO] isEnabledRightCornerICon:[NSNumber numberWithBool:NO]];
        [view_content4 setDelegate:self];
        
        [_view_content addSubview:view_content4];
        
        // 作死的写法
        for ( UIView *tmp in _view_content.subviews) {
            
            if ([tmp isMemberOfClass:[WalletCenterView class]]) {
              
                 self.defaultTag ++;
                [tmp setTag:self.defaultTag];
            }
        }
    }
    
    return _view_content;
}

- (UIButton *)button_saveMoney {
    
    if (!_button_saveMoney) {
        
        _button_saveMoney  = [UsefulUtil buttonCreationWithFrame:CGRectMake(MULTIPLYWIDTH(30.0/2), CGRectGetMaxY(self.view_content.frame) + MULTIPLYHEIGHT(40.0/2), SCREEN_WIDTH - MULTIPLYWIDTH(60.0/2), MULTIPLYHEIGHT(90.0/2)) textColor:[UIColor whiteColor] fontName:[UIFont systemFontOfSize:15.0] text:@"立即存入"];
        
        [_button_saveMoney setBackgroundColor:REDCOLOR];
        [_button_saveMoney addTarget:self action:@selector(buttonClickedAtWalletPage:) forControlEvents:UIControlEventTouchUpInside];
        
        [_button_saveMoney setTag:20];
    }
    
    return _button_saveMoney;
}

- (UIView *)view_bottom {
    
    if (!_view_bottom) {
        
        _view_bottom = [UsefulUtil viewCreationWithFrame:CGRectMake(MULTIPLYWIDTH(30.0/2), MULTIPLYHEIGHT(40.0/2) + CGRectGetMaxY(self.button_saveMoney.frame), SCREEN_WIDTH - MULTIPLYWIDTH(60.0/2), MULTIPLYHEIGHT(62.0/2)) backgroundColor:[UIColor whiteColor] backGroundImage:nil];
        
        [_view_bottom setClipsToBounds:YES];
        
        // 牛钱包投资协议
        
        UIButton *button_invest = [UsefulUtil buttonCreationWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(210.0/2), MULTIPLYHEIGHT(60.0/2)) textColor:[UsefulUtil colorWithHexString:@"#336699"] fontName:[UIFont boldSystemFontOfSize:15.0] text:@""];
        
        [_view_bottom addSubview: button_invest];
        
        UIImageView *image_invest = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(183.0/2), MULTIPLYHEIGHT(28.0/2))];
        
        [image_invest setImage:[UIImage imageNamed:@"wallet01"]];
        
        [button_invest addSubview:image_invest];
        
        // 什么是牛钱包
        
        UIButton *button_nameExplain = [UsefulUtil buttonCreationWithFrame:CGRectMake(SCREEN_WIDTH - MULTIPLYWIDTH(260.0/2), 0, MULTIPLYWIDTH(200.0/2), MULTIPLYHEIGHT(60.0/2)) textColor:[UsefulUtil colorWithHexString:@"#336699"] fontName:[UIFont boldSystemFontOfSize:15.0] text:@""];
        
        [_view_bottom addSubview: button_nameExplain];
        
        UIImageView *image_nameExplain = [[UIImageView alloc] initWithFrame:CGRectMake(MULTIPLYWIDTH(20.0/2), 0, MULTIPLYWIDTH(183.0/2), MULTIPLYHEIGHT(28.0/2))];
        
        [image_nameExplain setImage:[UIImage imageNamed:@"wallet02"]];
        
        [button_nameExplain addSubview:image_nameExplain];
        
        //添加事件
        
        [button_invest addTarget:self action:@selector(textExplain:) forControlEvents:UIControlEventTouchUpInside];
        [button_nameExplain addTarget:self action:@selector(textExplain:) forControlEvents:UIControlEventTouchUpInside];
        
        [button_invest setTag:30];
        [button_nameExplain setTag:31];
    }
    

    
    
    return _view_bottom;
}

- (NSMutableDictionary *)mutableDictionary_data {
    
    if (!_mutableDictionary_data) {
        
        _mutableDictionary_data = [NSMutableDictionary dictionary];
    }
    
    return _mutableDictionary_data;
}

#pragma mark - set rightbarbuttonItem

- (void) setRightBarButtonItemTitle:(NSString *) title imageName:(NSString *) name actionName:(SEL)action {
    
    // 图片在前，文字在后
    
    UIButton *button_rightItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(120.0/2), MULTIPLYHEIGHT(44.0))];
    [button_rightItem setTitle:title forState:UIControlStateNormal];
    [button_rightItem setTitleColor:[UsefulUtil colorWithHexString:@"#fb4747"] forState:UIControlStateNormal];
    [button_rightItem.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [button_rightItem addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    
    // 图片
    CALayer *layer_icon = [CALayer layer];
    
    [layer_icon setFrame:CGRectMake(0,MULTIPLYHEIGHT(27.0/2), MULTIPLYWIDTH(26.0/2), MULTIPLYHEIGHT(26.0/2))];
    [button_rightItem.layer addSublayer:layer_icon];
    
    
    [layer_icon setContents:(__bridge id)[UIImage imageNamed:name].CGImage];
    [button_rightItem setTitleEdgeInsets:UIEdgeInsetsMake(0, MULTIPLYWIDTH(8.0), 0, 0)];
    [button_rightItem.titleLabel setAdjustsFontSizeToFitWidth:YES];
    [button_rightItem.titleLabel setTextAlignment:NSTextAlignmentRight];
    UIBarButtonItem *barItemRight = [[UIBarButtonItem alloc] initWithCustomView:button_rightItem];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                       target:nil action:nil];
    /**
     *  width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和边界间距为5pix，所以width设为-5时，间距正好调整
     *  为0；width为正数时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacer.width = MULTIPLYWIDTH(-15.0);
    [self.navigationItem setRightBarButtonItems:@[negativeSpacer,barItemRight]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
